package com.huanghuai.retail.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huanghuai.retail.common.R;
import com.huanghuai.retail.entity.DeviceStatus;
import com.huanghuai.retail.mapper.DeviceStatusMapper;
import com.huanghuai.retail.service.DeviceService;
import com.huanghuai.retail.service.DeviceStatusService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DeviceStatusServiceImpl extends ServiceImpl<DeviceStatusMapper, DeviceStatus> implements DeviceStatusService {
    @Resource
    private DeviceService deviceService;

    @Override
    public R<String> saves(DeviceStatus deviceStatus) {
        if (deviceStatus == null) {
            return R.error("数据不存在！");
        }
        if (deviceStatus.getDeviceId() == null) {
            return R.error("设备id为空！");
        }
        if (deviceService.getById(deviceStatus.getDeviceId()) == null) {
            return R.error("设备不存在！");
        }
        save(deviceStatus);
        return R.success("添加成功");
    }

}
